package com.fenyin.samples.study.parttern.struct.adapter.example1;  

import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
  
/**
 *<p>IteratorEnumeration: 适配器类</p>
 *<p>Enumeration:适配器目标接口<p>
 *<p>iterator:适配器源对象<p>
 *@Title: 对象适配器模式
 *@Author:fengzhichao  
 *@Since:2012-9-29  
 *@Version:1.1.0
 */
public class IteratorEnumeration<T> implements Enumeration<T>{

	private static final Log log = LogFactory.getLog(IteratorEnumeration.class);
	
	private Iterator<T> iterator;
	
	public IteratorEnumeration(Iterator<T> iterator){
		this.iterator = iterator;
	}
	
	public boolean hasMoreElements() {
		return iterator.hasNext();
	}

	public T nextElement() {
		return iterator.next();
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public static void main(String[] args){
		List<String> list = new ArrayList<String>();
		list.add("fengzhichao");
		list.add("caimin");
		Iterator<String> iterator = list.iterator();
		Enumeration<String> enumeration = new IteratorEnumeration(iterator);
		while(enumeration.hasMoreElements()){
			log.info("数据元素:"+enumeration.nextElement());
		}
	}
}
